package com.dream.xiaobo.service.impl;

import com.dream.xiaobo.dao.AdminDao;
import com.dream.xiaobo.dao.impl.AdminDaoImpl;
import com.dream.xiaobo.entity.User;
import com.dream.xiaobo.service.AdminService;
import com.dream.xiaobo.utils.MD5Utils;

import java.sql.SQLException;

/**
 * @author xiaobo
 * @date 2021/9/4 - 13:31
 */
public class AdminServiceImpl implements AdminService {

    //创建管理员dao实例化对象
    private AdminDao adminDao = new AdminDaoImpl();

    /**
     * 判断登录接口实方法
     * @param username
     * @param password
     * @return
     * @throws SQLException
     */
    @Override
    public User selectAdminByName(String username,String password) throws SQLException {
        //将密码用MD5加密
        String md5Password = MD5Utils.md5(password);
        //调用根据用户名查询信息的方法
        User admin = adminDao.selectUserByName(username);
        //当查询到信息时和查询到的密码和输入的密码一致时
        if(null != admin && admin.getuPassword().equals(md5Password)){
            //返回信息
            return admin;
        }
        //返回空
        return null;
    }
}
